import { prisma } from "@/lib/prisma"
import { ExpenseList } from "@/components/expense/expense-list"
import { ExpenseHeader } from "@/components/expense/expense-header"
import { Metadata } from "next"
import { SerializedFinanceRecord } from "@/types"

export const metadata: Metadata = {
  title: "支出记录 - 商场销售系统",
  description: "支出记录页面",
}

export default async function ExpensePage() {
  const records = await prisma.financeRecord.findMany({
    where: {
      type: 'EXPENSE'
    },
    orderBy: {
      createdAt: 'desc'
    }
  })

  // 序列化数据
  const serializedRecords: SerializedFinanceRecord[] = records.map(record => ({
    ...record,
    amount: record.amount.toString(),
    createdAt: record.createdAt.toISOString(),
    updatedAt: record.updatedAt.toISOString()
  }))

  return (
    <div className="space-y-4 p-8">
      <ExpenseHeader />
      <ExpenseList records={serializedRecords} />
    </div>
  )
} 